package com.ftg.youx.demo.routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者  （发布者）
 *
 * @author 布衣
 */
public class Product {

    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        factory.setUsername("guest");
        factory.setPassword("guest");
        try(
            Connection connection =  factory.newConnection();
            //创建频道
            Channel channel = connection.createChannel();
        ) {
            //创建交易所
            channel.exchangeDeclare("myExchange", "direct");

            //发送信息
            String message = "撤销工资上涨通知";
            channel.basicPublish("myExchange","manager",null,message.getBytes());
            channel.basicPublish("myExchange","boss",null,message.getBytes());
            System.out.println("我发送完成了");

        } catch (IOException | TimeoutException e) {
            throw new RuntimeException(e);
        }
    }
}
